package com.icode.core.dto.house;

import com.icode.core.model.house.Equipment;
import com.icode.core.model.house.EquipmentType;
import org.joda.time.DateTime;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: SunKai
 * Date: 14-11-15
 * Time: 下午4:14
 * To change this template use File | Settings | File Templates.
 */
public class EquipmentDTO {
    private String name;
    private String type;
    private String createDate;
    private String guid;

    public EquipmentDTO() {
    }

    public EquipmentDTO(String name, DateTime dateTime, String guid,String type) {
        this.name = name;
        String createDate = String.valueOf(dateTime).substring(0, 10);
        this.createDate = createDate;
        this.guid = guid;
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public String getGuid() {
        return guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public static EquipmentDTO toDTO(Equipment equipment) {
        return new EquipmentDTO(equipment.name(), equipment.createTime(), equipment.guid(),equipment.type().name());
    }

    public Equipment toEquipments(EquipmentType equipment) {
        return new Equipment(this.name, equipment);
    }

    public static List<EquipmentDTO> toDTOs(List<Equipment> equipments) {
        List<EquipmentDTO> equipmentDTOs = new ArrayList<>();
        for (Equipment equipment : equipments) {
            EquipmentDTO equipmentDTO = new EquipmentDTO(equipment.name(), equipment.createTime(), equipment.guid(),equipment.type().name());
            equipmentDTOs.add(equipmentDTO);
        }
        return equipmentDTOs;
    }
}
